package healthyPointsManager.component
{
	import mx.validators.NumberValidator;
	import mx.validators.ValidationResult;	
	
	public class CustomNumberValidator extends NumberValidator
	{
		private const ZERO:Number = 0;
		private const ONE_HALF:Number = .5;
		private var results:Array;
		
		public function CustomNumberValidator()
		{
			//TODO: implement function
			super();
		}
		
		override protected function doValidation(value:Object):Array{			
			//get incoming number value (assumes this is a number, thus it's a number validator rather than a generic validator...
			var inputValue:Number = Number(value);
			
			//clear array for current validation
			results = [];			
			results = super.doValidation(value);
			if(results.length > 0 || !this.required){
				return results;
			}			
			var intValue:int = int(value);//int copy
	    	var decmal:Number = Number(value);//whole copy
	    	decmal = decmal - intValue;//should be left with only the decmal value
	    	if(decmal != ZERO && decmal != ONE_HALF){
	    		results.push(new ValidationResult(true, null, "improperFaction", "The number entered must be a half or whole value (e.g. 10.5, 11)."));
	    	}
	    	return results;
		}		
	}
}